/**
 * 
 */
package bus;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
 * @spring.bean id="loginValidator"
 * @author ipeel
 *
 */
public class LoginValidator implements Validator{

	/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */
	public boolean supports(Class clazz) {
		return clazz.equals(Login.class);
	}

	/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
	 */
	public void validate(Object obj, Errors errors) {
		Login loginForm = (Login)obj;
		if(loginForm.getUsername().equals("")) {
			errors.rejectValue("username", "error.not-specified", null, "Username is required.");
		}
		
		if(loginForm.getPassword().equals("")) {
			errors.rejectValue("password", "error.not-specified", null, "Password is required.");
		}
	}
}
